#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cmath>
using namespace std;

double NewtonRalphson(double x)
{
	if (x == 0)
		return 0;
	const double ACCURACY = 1e-5;
	double root = 1;
	double tmp = fabs(x);
	do
	{
		root = (root + tmp / root) / 2;
	} while (fabs(root*root - tmp) > ACCURACY);
	return root;
}
int main()
{
	double x;
	cout << "Please input a real number:>";
	while (cin >> x)
	{
		double root = NewtonRalphson(x);
		cout << "Its square root is: ";
		if (x >= 0)
		{
			cout << root << endl<<endl;
		}
		else
		{
			if (root != 1)
			{
				cout << root << "i" << endl << endl;
			}
			else
			{
				cout << "i" << endl << endl;
			}
		}
		cout << "Please input a real number:>";
	}
	return 0;
}